package com.shujia.partition;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class MyPartition extends Partitioner<Text, NullWritable> {
    /*
    * 1.定义分区规则
    * 2.返回对应分区编号
    * */
    public int getPartition(Text text, NullWritable nullWritable, int numPartitions) {
        //1。拆分行文本数据(K2),年龄字段的值
        String[] split = text.toString().split(",");
        String numStr = split[2];

        //2.判断字段与22的关系，然后返回对应分区编号
        if(Integer.parseInt(numStr) > 22){
            return 1;
        }else {
            return 0;
        }
    }
}
